﻿<?php
/**
 * Classe MAPPER da tabela TB_PARAM_CLASSE
 * 
 * @author			Mário R. Castro
 * @copyright		Voitech Sistema
 * @package			SEMAS
 * @subpackage		semas.application.models
 * @version			1.0
*/
class App_Model_ParamClasseMapper extends Voitech_Mapper{

    public function __construct(App_Model_ParamClasse $obParamClasse){
        $this->obModel = $obParamClasse;
    }    
    
    public function buscarPorId() {}
    
    public function carregar(stdClass $obRow) {
        $this->obModel->setCoClasse($obRow->co_classe);
        $this->obModel->setNoClasse($obRow->no_classe);
        $this->obModel->setStStatus($obRow->st_status);
        $this->obModel->setFlagExcluir($obRow->fl_excluir);
        $this->obModel->setDtCadastro($obRow->dt_cadastro);
        return $this;
    }

    
    public function cadastrar() {
        $arParamClasse = $this->retornarArrayPopulado();     
        return App_Model_Db_ParamClasse::build()->insert($arParamClasse);                                         
    }
    
    public function alterar(){
        $arParamClasse = $this->retornarArrayPopulado();        
        return App_Model_Db_ParamClasse::build()->update($arParamClasse,App_Model_Db_ParamClasse::build()->getAdapter()->quoteInto('co_classe = ?',$this->obModel->getCoParamClasse()));                
    }

    public function retornarArrayPopulado() {
        $arrParamClasse = array('no_classe'=>$this->obModel->getNoParamClasse());
       
        if( $this->obModel->getCoParamClasse() != '' ) {
            $arrParamClasse['co_classe'] = $this->obModel->getCoParamClasse();
        }
        return $arrParamClasse;
    }

    public function ativar() {
        if($this->obModel->getCoParamClasse() == ''){
            throw new Voitech_Exception('Falta cod. da Classe');
        }
        $arrUpdate = array('st_ativo'=>'S');       
        return App_Model_Db_ParamClasse::build()->update($arrUpdate,App_Model_Db_ParamClasse::build()->getAdapter()
                                                                                            ->quoteInto('co_classe = ?',$this->obModel->getCoParamClasse()));                
    }
    
    public function desativar() {
        if($this->obModel->getCoParamClasse() == ''){
            throw new Voitech_Exception('Falta cod. da Classe');
        }
        $arrUpdate = array('st_ativo'=>'N');
        return App_Model_Db_ParamClasse::build()->update($arrUpdate
                                                   ,App_Model_Db_ParamClasse::build()->getAdapter()
                                                                                ->quoteInto('co_classe = ?',$this->obModel->getCoParamClasse()));                
    }
      
    public function excluir() {
        if($this->obModel->getCoParamClasse() == ''){
            throw new Voitech_Exception('Falta cod. da Classe');
        }
        return App_Model_Db_ParamClasse::build()->delete(App_Model_Db_ParamClasse::build()->getAdapter()->quoteInto('co_classe = ?',$this->obModel->getCoParamClasse()));                
    }
	
}